<?php
require_once "Zend/Service/Exception.php";

class Zend_Service_Netflix {

	/**
	 * Netflix API URI
	 */
	const URI_BASE = "http://api.netflix.com";
	
	/**
	 * NETFLIX API-USER URI
	 */
	const API_USER_URI_BASE = "https://api-user.netflix.com";
	
	/**
	 * OAuth Signiture Method.
	 * HMAC-SHA1 OR PLAINTEXT
	 */
	const SIGNITURE_METHOD = 'PLAINTEXT';
	
	/**
	 * OAuth Version
	 */
	const VERSION = '1.0';
	
	/**
	 * Shared Secret.
	 *
	 * @var unknown_type
	 */
	protected $_sharedSecret   = '';
	
	/**
	 * Consumer Key. (Application Id)
	 *
	 * @var unknown_type
	 */
	protected $_consumerKey = '';

	/**
	 * Rest Object. Used for REST calls.
	 *
	 * @var unknown_type
	 */
	protected $_restClient  = null;
	
	/**
	 * Generated Request Token Secret by Netflix.
	 *
	 * @var unknown_type
	 */
	public $_requestTokenSecret  = '';
	
	/**
	 * Generated Request Token from Netflix.
	 *
	 * @var unknown_type
	 */
	public $_requestToken;
	
	/**
	 * Generated Application Name returned by Netflix
	 *
	 * @var unknown_type
	 */
	protected $_applicationName;
	
	/**
	 * Access Token Required to Access User data.
	 *
	 * @var unknown_type
	 */
	public $_accessToken;
	
	/**
	 * Access Token Secret Required To Access User data.
	 *
	 * @var unknown_type
	 */
	public $_accessTokenSecret;
	
	/**
	 * User Id Generated By Netflix.
	 *
	 * @var unknown_type
	 */
	public $_userId;


	/**
	 * Return the Access Token.
	 *
	 * @return String
	 */
	public function getAccessToken(){
		return $this->_accessToken;
	}
	
	/**
	 * Return the Access Token Secret
	 *
	 * @return String
	 */
	public function getAccessTokenSecret(){
		return $this->_accessTokenSecret;
	}
	
	/**
	 * Return the user id.
	 *
	 * @return String
	 */
	public function getUserId(){
		return $this->_userId;
	}
	
	public function setAccessToken($accessToken){
		$this->_accessToken = $accessToken;
	}
	
	public function setAccessTokenSecret($accessTokenSecret){
		$this->_accessTokenSecret = $accessTokenSecret;
	}
	
	/**
	 * Constructor.
	 *
	 * @param String $applicationId
	 * @param String $sharedSecret
	 */
	public function __construct($applicationId, $sharedSecret){
			
		if(!empty($applicationId)){
			$this->_consumerKey   = $applicationId;
		}else{
			
			throw new Zend_Service_Exception("Application ID Required.");
		}
		
		if(!empty($sharedSecret)){
			
			$this->_sharedSecret  = $sharedSecret;
			
		}else{
			
			throw new Zend_Service_Exception("Shared Secret Required.");
		}	
			
	}
	
	
	
	
	/*****************************
	 * CATALOG
	 *****************************/
	
	/**
	 * Returns a list of Titles from Netflix
	 * 
	 * Option Values:  
	 * start_index=0, max_results=25
	 * 
	 * 
	 * @param String $term
	 * @param array $options
	 * @return NetflixCatalog
	 */
	public function getTitles($term, array $options=array()){
		
		//Validate term
		if(empty($term)){
			throw new Zend_Service_Exception("Auto Complete Term Can Not Be Empty.");	
		}
		
		//Method
		$method = "/catalog/titles";
		
		//Options
		$options['term'] = urlencode($term);
		$options         = $this->buildOptions($options);
		
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($method, $options);
		
		//Check if there are errors
		if(!$response->isError()){
			
			//Get the response
			$content = $response->getBody();
			
			//Create Catalog Object
			$simpleXml = simplexml_load_string($content);
			
			require_once "Netflix/Catalog.php";
			$NetflixCatalog = new Netflix_Catalog();
			$NetflixCatalog->loadXML($simpleXml);
			
			return $NetflixCatalog;
			
		}else{
			
			throw new Zend_Service_Exception($response->getMessage());
			
		}
	
		
	}
	
	
	/**
	 * Returns a specific title based on 
	 * the type.
	 * 
	 * Required Values:
	 * id, type={movie|series|seasons|program|discs}
	 * 
	 * Option Values:  
	 * start_index=0, max_results=25
	 * 
	 * 
	 * @param String $term
	 * @param array $options
	 * @return unknown
	 */
	public function getTitle($id, $type, array $options=array()){
		
		//Validate id
		if(empty($id)){
			throw new Zend_Service_Exception("Id Can Not Be Empty.");	
		}
		
		if(empty($type)){
			throw new Zend_Service_Exception("Type Can Not Be Empty.");	
		}
		
		//Method
		if($type == "movie"){
			$method = "catalog/titles/movies/".$id;
		}
		elseif($type == "series"){
			$method = "catalog/titles/series/".$id;
		}
		elseif($type == "seasons"){
			$method = "catalog/titles/series/".$id."/seasons";
		}		
		elseif($type == "programs"){
			$method = "catalog/titles/programs/".$id;
		}		
		elseif($type == "discs"){
			$method = "catalog/titles/discs/".$id;
		}
		

		//Options
		$options = $this->buildOptions($options);
		
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($method, $options);
	
		//Check if there are errors
		if(!$response->isError()){
			
			//Get the response
			$content = $response->getBody();
			
			//Create Catalog Object
			$simpleXml = simplexml_load_string($content);
			
			require_once "Netflix/Title.php";
			$NetflixCatalog = new Netflix_Title();
			$NetflixCatalog->loadXML($simpleXml);
		
			return $NetflixCatalog;
			
		}else{
			
			throw new Zend_Service_Exception($response->getMessage());
			
		}
	
		
	}


	/**
	 * Search for movies and tv series based on full title
	 * or partial title text.
	 * 
	 * @param String $term "Hunt for Red"
	 * @return Array Collection of Full Titles Found.
	 */
	public function getTitlesAutoComplete($term){
		
		//Validate term
		if(empty($term)){
			throw new Zend_Service_Exception("Auto Complete Term Can Not Be Empty.");	
		}
		
		//Initialize titles to return
		$titles = array();
		
		//Method
		$method = "/catalog/titles/autocomplete";
		
		//Options
		$options['term'] = urlencode($term);
		$options         = $this->buildOptions($options);

		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($method, $options);

		//Check for errors
		if(!$response->isError()){
			
			//Get the content 
			$content = $response->getBody();
		
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);

			//Parse the results
			foreach($simpleXMLObj->autocomplete_item as $autocompleteItem){
				
				foreach($autocompleteItem as $title){
					array_push($titles, (string)$title['short']);
				}
			}
			
			return $titles;
			
		}else{
			
			throw new Zend_Service_Exception($response->getMessage());
			
		}	
		
	}

	
	/**
	 * Returns a Catalog containing a list of 
	 * similar titles.
	 *
	 * Required Params:
	 * 1.  id
	 * 
	 * Options Params
	 * 1. start_index=0
	 * 2. max_results=25
	 * 
	 * 
	 * @param string $id title id.
	 * @param array $options
	 */
	public function getSimilarTitles($id, array $options=array()){
		
		//Validate id
		if(empty($id)){
			throw new Zend_Service_Exception("Missing Id.");
		}
		
		//Method
		$method = "/catalog/titles/".$id."/similars";
		
		//Options
		$options = $this->buildOptions($options);
		
		//Call REST Api.
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($method, $options);
		
		//If there are errors throw exception otherwise process.
		if(!$response->isError()){
			
			//Get the content 
			$content = $response->getBody();
			
			//Create SimpleXML Object 
			$xml = simplexml_load_string($content);

			require_once "Netflix/Title.php";
			$NetflixCatalog = new Netflix_Title();
			$NetflixCatalog->loadXML($xml);
			
			return $NetflixCatalog;
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}
	
	
	/**
	 * Returns a list of people matching the term 
	 * passed into the initial parameter.
	 *
	 * Options Params
	 * 1. start_index=0
	 * 2. max_results=25 
	 * 
	 * @param String $name 
	 * @param array $options
	 */
	public function getPeople($name, array $options=array()){

		//Validate name
		if(empty($name)){
			throw new Zend_Service_Exception("Missing parameter.");
		}
		
		//Method
		$method = "/catalog/people";
		
		//Options
		$options['term'] = urlencode($name);
		$options 		 = $this->buildOptions($options);
		
		//Call REST Api
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($method, $options);
		
		if(!$response->isError()){
			
			//Get the content 
			$content = $response->getBody();
			
			//Create SimpleXML Object 
			$xml = simplexml_load_string($content);

			require_once "Netflix/Person.php";
			
			//Replace bottom with a call to a People class.
			$people = array();
			foreach($xml->person as $person){
			
				$NetflixPerson = new Netflix_Person();
				$NetflixPerson->loadXML($person);
				array_push($people, $NetflixPerson);
			}
			
			return $people;
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}
	
	
	
	/**
	 * Return specific person.
	 *
	 * @param unknown_type $personId
	 * @param array $options
	 * @return unknown
	 */
	public function getPerson($personId, array $options=array()){
		
		//Validate name
		if(empty($personId)){
			throw new Zend_Service_Exception("Missing parameter.");
		}
		
		//Method
		$method = "/catalog/people/".$personId;
		
		//Options
		$options = $this->buildOptions($options);
		
		//Call REST Api
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($method, $options);
		
		if(!$response->isError()){
			
			//Get the content 
			$content = $response->getBody();
			
			//Create SimpleXML Object 
			$xml = simplexml_load_string($content);

			require_once "Netflix/Person.php";
			$NetflixPerson = new Netflix_Person();
			$NetflixPerson->loadXML($xml);
			
			return $NetflixPerson;
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
	}

	/*******************************
	 * USER API CALLS
	 *******************************/
	
	/**
	 * Return user Infomation.
	 *
	 * @param String $userId
	 * @return unknown
	 */
	public function getUser($userId){
		
		//Check if the user id is not empty
		if(empty($userId)){
			throw new Exception("Missing UserID Parameter.");
		}
		
		//Method
		$path = "/users/".$userId;
		
		//Options
		$options = $this->buildOptions(array(), true);
		
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}

	/*************************
	 * MANAGING QUEUES
	 *************************/
	
	/**
	 * Returns a Queue
	 * 
	 * $type = {disc | instant | }
	 * $status = available | saved
	 *
	 * @param unknown_type $userId
	 * @param unknown_type $type
	 * @param array $options
	 */
	public function getQueue($userId, $type='', $status = '', array $options=array()){}
	/*
	users/userID /queues
	users/userID /queues/disc
	users/userID /queues/disc/available
	users/userID /queues/disc/saved
	users/userID /queues/instant
	users/userID /queues/instant/available
	users/userID /queues/instant/saved
	*/
	
	
	public function deleteFromQueue($userId, $type, $entyId){
		
	/*
	users/userID /queues/disc/available/entryID
	users/userID /queues/disc/saved/entryID
	users/userID /queues/instant/available/entryID
	users/userID /queues/instant/saved/entryID
	*/
		
	}
	
	public function addToQueue($userId, $type, $entyId){
		
			
	/*
	users/userID /queues/disc/available/entryID
	users/userID /queues/disc/saved/entryID
	users/userID /queues/instant/available/entryID
	users/userID /queues/instant/saved/entryID
	*/
		
	}
	
	
	/*************************
	 * UPDATING QUEUE
	 **************************/
	
	public function getDiscQueue($userId, $type='available'){}
	
	
	
	/*************************
	 * TRACKING
	 *************************/
	public function getTitlesAtHome($userId, array $options=array()){
		
		//Check userid is not null
		if(empty($userId)){
			throw new Exception("Missing UserId Parameter.");
		}
		
		//Check which api call we need to make.
		$path = "users/".$userId."/at_home";
		
		
		//Build Options
		$options = $this->buildOptions($options, true);
		
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}
	
	
	
	
	/************************
	 * RENTAL HISTORY
	 ************************/
	
	/**
	 * Return a the rental history for the user.
	 * 
	 * history {all, shipped, returned, watched}
	 * options {start_index, max_results, updated_min}
	 * 
	 * @param unknown_type $userId
	 * @param unknown_type $historyType
	 * @param array $options
	 * @return unknown
	 */
	public function getRentalHistory($userId, $historyType='all', array $options=array()){
		
		//Check userid is not null
		if(empty($userId)){
			throw new Exception("Missing UserId Parameter.");
		}
		
		//Check which api call we need to make.
		$path = "users/".$userId."/rental_history";
		
		if($historyType == "shipped"){
			$path .= "/shipped";
		}
		elseif($historyType  == "returned"){
			$path .= "/returned";
		}
		elseif($historyType == "watched"){
			$path .= "/watched";
		}
		
		//Build Options
		$options = $this->buildOptions($options, true);
		
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}
	
	
	
	
	
	
	
	/**
	 * Returns an array of Netflix_Review objects 
	 * partaining to the user's review or reviews the 
	 * user made on a list of titles.
	 *
	 * Options Params
	 * 1. start_index=0
	 * 2. max_results=25 
	 * 3. updated_min
	 * 
	 * @param unknown_type $userId
	 * @param array $titles
	 * @return unknown
	 */
	public function getReviews($userId, array $titles=array(), array $options=array()){
		
		//Format the titles array
		$titles = implode(",", $titles);
		
		//Initialize reviews.
		$reviews = array();
		
		//Path.
		$path = "users/".$userId."/reviews";
		
		//Options
		$options = array("title_refs" => $titles);
		$options = $this->buildOptions($options, true);
					
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $query);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			//Parse the results
			require_once "Netflix/Review.php";
			foreach($simpleXMLObj->reviews->review as $review){
				array_push($reviews, new Netflix_Review($review));
			}
		
			return $reviews;
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}

	}
	
	
	public function getRecommendations($userId, array $options=array()){
		
		//Check if the user id is not empty
		if(empty($userId)){
			throw new Exception("Missing UserID Parameter.");
		}
		
		//Method
		$path = "/users/".$userId."/recommendations";
		
		//Options
		$options = $this->buildOptions($options, true);
		
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			
		
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
		
	}
	
	public function getRatings($userId, array $title=array()){
	
		//Format the titles array
		$titles = implode(",", $titles);
		
		
		//Path.
		$path = "/users/".$userId."/ratings";
		
		//Options
		$options = array("title_refs" => $titles);
		$options = $this->buildOptions($options, true);
					
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
		
	}
	
	
	public function addRating($userId, $title, $rating){
		
		//Check if the userId is not null
		
		//Check if the title is not null
		
		//Check if the rating is 1 and 5
		
		
		//Path.
		$path = "/users/".$userId."/ratings/title/actual";
		
		//Options
		$options = array("title_refs" => $title,
						 "rating"     => $rating);
						 
		$options = $this->buildOptions($options, true);
					
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restPost($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
		
	}
	
	public function updateRating($userId, $ratingId, $rating){
		
		//Check if the userId is not null
		
		//Check if the ratingId is not null
		
		//Check if the rating is 1 and 5
		
		
		//Path.
		$path = "/users/".$userId."/ratings/title/actual/".$ratingId;
		
		//Options
		$options = array("rating"     => $rating);
						 
		$options = $this->buildOptions($options, true);
					
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restPut($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}


	public function getPredictRating($userId, array $titles=array()){
		
		//Format the titles array
		$titles = implode(",", $titles);
			
		//Path.
		$path = "/users/".$userId."/ratings/title/predicted";
		
		//Options
		$options = array("title_refs" => $titles);
		$options = $this->buildOptions($options, true);
					
		//Call REST API
		$restClient = $this->getRestClient();
		$response   = $restClient->restGet($path, $options);
		
		//Check if there were any errors
		if(!$response->isError()){

			//Get the body of the response.
			$body = $response->getBody();
			
			//Create SimpleXML Object 
			$simpleXMLObj = simplexml_load_string($content);
			
			
			return '';
			
		}else{
			throw new Zend_Service_Exception($response->getMessage());
		}
		
	}

	
	
	/**
	 * Get an instance of a rest client to use
	 *
	 * @return Zend_Rest_Client
	 */
	protected function getRestClient(){
		
		if($this->_restClient === null){
		
			require_once "Zend/Rest/Client.php";
			$this->_restClient = new Zend_Rest_Client(self::URI_BASE);
				
		}
		
		return $this->_restClient;
		
	}
	
	/**
	 * Creates a randomly generated value used in the 
	 * oauth_nonce parameter.
	 *
	 * @return string
	 */
	protected function getOAuthNOnce(){
		
		return time();
	}
	
	   
	/**
	 * Generate time stamp.  Used as
	 * oauth_timestamp parameter value.
	 *
	 * @return unknown
	 */
	protected function getOAuthTimeStamp(){
		
		return time();
		
	}
	
	
	/**
	 * Generate the Oauth Default Options that is required for all calls.
	 *
	 * @return unknown
	 */
	protected function getOauthDefaultOptions($enableAccessToken=false){
		
		
		$defaultOptions = array("oauth_consumer_key"     	=> $this->_consumerKey,
							    "oauth_nonce"			  	=> self::getOAuthNOnce(),
							    "oauth_signature"			=> urlencode($this->_sharedSecret."&"),
							    "oauth_signature_method" 	=> self::SIGNITURE_METHOD,
					   		    "oauth_timestamp"        	=> self::getOAuthTimeStamp(),
					   		    "oauth_version" 			=> self::VERSION);

		//If AccessToken Options are enabled add more options
		if($enableAccessToken){
			$defaultOptions['oauth_token']	    = $this->_accessToken;
			$defaultOptions['oauth_signature']	= urlencode($this->_sharedSecret."&".$accessTokenSecret);   		    
		}
					   		     
		return $defaultOptions;			   
					   
	}
	
	
	
	/**
	 * Buld options to send to the API call.
	 *
	 * @param array $options
	 * @return array $options
	 */
	protected function buildOptions(array $options=array(), $enableAccessToken=false){
		
		return array_merge($options, $this->getOauthDefaultOptions($enableAccessToken));
		
	}
	
	
	/**
	 * Get the request token information from Netflix.
	 */
	protected function getRequestTokenData(){
		
		//Method to call.
		$method = "/oauth/request_token";
		
		//Options.
		$options  = $this->getOauthDefaultOptions();
		
		
		try{
			
			$restClient = $this->getRestClient();
			$response = $restClient->restGet($method, $options);
		
		
			//Get the body to parse the token info.
			$content = $response->getBody();
			$params  = explode("&", $content);
			
			foreach($params as $param){
				
				$values = explode("=", $param);
				
				if($values[0] == "oauth_token_secret"){
					$this->_requestTokenSecret = $values[1];
				}
				
				if($values[0] == "oauth_token"){
					$this->_requestToken = $values[1];
				}
				
				if($values[0] == "application_name"){
					$this->_applicationName = $values[1];
				}
				
			}	
		
		}catch(Zend_Exception $e){
			
		}
		
	}
		
	/**
	 * Generates URL to allow users to provide access to their 
	 * info. 
	 * 
	 * <p>
	 * Response generates user_id, access_token, and acess_token_secret
	 * This data is unique to each user and must be stored locally if 
	 * application needs to use it at a future date.
	 * </p>
	 * 
	 * @param unknown_type $callbackURL
	 * @return unknown
	 */
	public function getRequestTokenAuthorizationURL($callbackURL){
		
		//Generate the Request Token data.
		$this->getRequestTokenData();
		
		//Append requestToken and requestSecretKey.
		$appendQuery = "?request_token=".$this->_requestToken.
					   "&request_token_secret=".$this->_requestTokenSecret;
					   
		$callbackURL = $callbackURL.$appendQuery;
		
		
		$method = "/oauth/login";
		
		$query = "?application_name=".$this->_applicationName.
				 "&oauth_token=".$this->_requestToken.
				 "&oauth_consumer_key=".$this->_consumerKey.
				 "&oauth_callback=".urlencode($callbackURL);
		
		$url    = self::API_USER_URI_BASE.$method.$query;
		return $url;

	}
	
	
	/**
	 * Generate Access Token Data.
	 *
	 * @param unknown_type $requestedToken
	 * @param unknown_type $requestedTokenSecret
	 */
	public function getAccessTokenData($requestedToken, $requestedTokenSecret){
		

		$method = "/oauth/access_token";
		
		$defaultOptions = array("oauth_consumer_key"     	=> $this->_consumerKey,
							    "oauth_nonce"			  	=> self::getOAuthNOnce(),
								"oauth_signature"			=> urlencode($this->_sharedSecret."&".$requestedTokenSecret),
							    "oauth_signature_method" 	=> self::SIGNITURE_METHOD,
					   		    "oauth_timestamp"        	=> self::getOAuthTimeStamp(),
					   		    "oauth_token"				=> $requestedToken,
					   		    "oauth_version" 			=> self::VERSION);
		   		    
		try{
			
			$restClient = $this->getRestClient();
			$response = $restClient->restGet($method, $defaultOptions);
		
			$content = $response->getBody();
			//Parse out the access token information
			
			echo $content;
			$params  = explode("&", $content);
			
			foreach($params as $param){
				
				$values = explode("=", $param);
				
				if($values[0] == "user_id"){
					$this->_userId = $values[1];
				}
				
				if($values[0] == "oauth_token"){
					$this->_accessToken = $values[1];
				}
				
				if($values[0] == "oauth_token_secret"){
					$this->_accessTokenSecret = $values[1];
				}
				
			}	
			
			
		}catch(Zend_Exception $e){
			echo $e->getMessage();
			
		}
	
		
	}

}
?>
